home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 May: Tool Chest / Dev.CD May 00 TC.toast / pc / tool chest / development kits / hypercard related / hypercard instance variables / instance variables / stack_-1.xml < prev    next >
Encoding:
Extensible Markup Language  |  1993-04-01  |  10.5 KB  |  35 lines

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE stack PUBLIC "-//Apple, Inc.//DTD stack V 2.0//EN" "" >
  3. <stack>
  4.     <name>in</name>
  5.     <id>-1</id>
  6.     <cardCount>16</cardCount>
  7.     <cardID>3026</cardID>
  8.     <listID>4203</listID>
  9.     <cantModify><false /></cantModify>
  10.     <cantDelete><false /></cantDelete>
  11.     <cantAbort><false /></cantAbort>
  12.     <cardSize>
  13.         <width>512</width>
  14.         <height>342</height>
  15.     </cardSize>
  16.     <script>-- Allow Instance Variables for buttons, fields, cards, and backgrounds.
  17. -- (c) 1991, 1992 copyright Apple Computer, all rights reserved.
  18. -- Version 1.0 for HyperCard 2.1
  19.  
  20. -- This belongs in the stack script of your stack.
  21. -- (Just putting it in the Home script is not the best.  If you give
  22. --  your stack to someone, instance variables will stop working.)
  23.  
  24. -- You call these: putVar, getVar, allowInstVars
  25. -- Bonus handlers: removeVar, hasThisVar, allVarsOf
  26. -- Internal use only: instVar, createBkgndFld, ss, hh
  27.  
  28. on putVar cdBk,myID,variable,value,cardID
  29. -- Store the value of this variable in this object
  30. -- Example:  putVar cd,the id of me,fred,45
  31. --    a missing cardID means on the current card
  32. -- cdBk is cd or bk
  33. --    (where is this object? cd is card, bk is background)
  34. -- myID is: the short id of me
  35. -- variable is the name under which you want to store this value
  36. -- value is what you want to store
  37. --   value may not contain { or } characters
  38. -- cardID (optional) the id of the card that contains the object
  39.  
  40. put instVar(cdBk,myID,variable,value,cardID) into dummy
  41. end putVar
  42.  
  43.  
  44. function getVar cdBk,myID,variable,cardID
  45. -- Retrieve the value of this variable in this object
  46. -- Example:  getVar cd,the id of me,fred
  47. --    a missing cardID means on the current card
  48. -- cdBk is cd or bk
  49. --    (where is this object? cd is card, bk is background)
  50. -- myID is: the short id of me
  51. -- variable is the name under which you want to store this value.
  52. --   variable may not contain { or } characters
  53. --   it may contain spaces or other characters
  54. -- cardID (optional) the id of the card that contains the object
  55.  
  56. return instVar(cdBk,myID,variable,"{}",cardID)  --retrieval
  57. end getVar
  58.  
  59.  
  60. function instVar cdBk,myID,variable,value,cardID
  61. -- Get or put the value of a variable that belongs to a
  62. -- card button, card field, the card itself, a bkgnd button,
  63. -- shared field, or the bkgnd itself.
  64.  
  65. -- User should not call this. Called from getVar, putVar and removeVar.
  66.  
  67. -- Instance variables for bkgnd fields are not supported!  This is
  68. -- because it a background field is part shared and part local to
  69. -- the card.  Attach the variable to the card or to a shared
  70. -- field instead.
  71.  
  72. -- Works for both storing and retireving, for both objects on a
  73. -- card and object shared across a background.
  74.  
  75. -- If value is "{}" then we are retrieving a value from the
  76. -- dictionary.
  77.  
  78. -- Note that myID is not enough information to actually find the
  79. -- button or field (we don't know which it is).  But we don't
  80. -- care.  We don't have to get at the button or field itself,
  81. -- just find it's variables in the dictionary!
  82.  
  83. -- The search keys
  84. put "{" & variable & "{" & myID & "{" into startKey    --{Fred{21{
  85. put "}" & variable & "}" & myID & "}" into endKey      --}Fred}21}
  86.  
  87. if cardID is empty
  88. then put the short id of this card into holder  -- on current card
  89. else put cardID into holder   --on a specific card
  90.  
  91. if cdBk = "bk"
  92. then put "call allowInstVars first" into theFld  --background objects
  93. else put "you must call allowInstVars" into theFld  --card specific
  94. --  The names of these fields are funny so that the user will know
  95. --  what to do when he gets and error because the fields are not there.
  96.  
  97. -- If the field is missing, you must call allowInstVars (just once in
  98. -- each background) to initialize some hidden fields.
  99. put offset(startKey,bkgnd fld theFld of cd id holder) ¬¨
  100. into startLoc    --loc of {Fred{21{
  101.  
  102. if startLoc is 0 then
  103. --the key wasn't found
  104. if (cdBk is not "cd") and (cdBk is not "bk")
  105. then answer "First arg of putVar must be bk or cd" with "OK"
  106.  
  107. if value = "{}" then   --getting and it was not found
  108. put cdBK && "id" && myID && variable && "on card" && holder
  109. answer "You must putVar into a variable" & return &¬¨
  110. "before using getVar to read it."
  111. return "no value in:" && variable
  112. else
  113. --putting a value, create a new variable
  114. put return & startKey & value & endKey after bkgnd fld ¬¨
  115. theFld of cd id holder
  116. return value
  117. end if
  118. end if
  119.  
  120. put offset(endKey,bkgnd fld theFld of cd id holder) ¬¨
  121. into endLoc    --loc of }Fred}21}
  122.  
  123. add length(startKey) to startLoc   --loc after key, start of value
  124. subtract 1 from endLoc
  125. if value = "{}" then   --getting a value
  126. -- Retrieve the value of the variable
  127. return char startLoc to endLoc of bkgnd fld theFld of cd id holder
  128. else
  129. if value = "re{}move" then
  130. --remove the variable to save space
  131. subtract length(startKey) from startLoc   --loc before key
  132. add length(startKey) to endLoc   --loc after end key
  133. put empty into char startLoc to endLoc of bkgnd fld ¬¨
  134. theFld of cd id holder  -- remove keys and value
  135. else
  136. -- Store the value in the dictionary over old value
  137. put value into char startLoc to endLoc of bkgnd fld ¬¨
  138. theFld of cd id holder
  139. end if
  140. return value
  141. end if
  142. end instVar
  143.  
  144. on allowInstVars
  145. -- Create a field for the instance variable dictionary.
  146. -- It has a funny name so the user will know what to do
  147. -- when he gets and error because the field is not there.
  148. createBkgndFld "you must call allowInstVars"  --card variables
  149. createBkgndFld "call allowInstVars first"  --bkgnd variables
  150. set sharedText of bkgnd fld "call allowInstVars first" to true
  151. set loc of bkgnd fld "call allowInstVars first" to 160,250
  152. end allowInstVars
  153.  
  154. on createBkgndFld  theName
  155. -- Create hidden background field if not there already.
  156. -- Use this field for storing the dictionary of names and values.
  157. repeat with ii = 1 to the number of bkgnd fields
  158. put the short name of bkgnd field ii into myName
  159. if myName is theName
  160. then
  161. put "already there!"
  162. exit createBkgndFld  --already exists
  163. end if
  164. end repeat
  165.  
  166. -- Create a background field for the instance variable dictionary.
  167. doMenu "background"
  168. doMenu "New Field"
  169. put the number of bkgnd fields into num
  170. set the name of field num to theName
  171. hide field theName   -- important!
  172. choose browse tool
  173. doMenu "Background"    --get out of Background mode
  174. put "new is " & num  --debugging
  175. end createBkgndFld
  176.  
  177. on removeVar cdBk,myID,variable,cardID
  178. -- Remove this variable in this object
  179. -- Is not necessary.  Only do it to save space when destroying
  180. -- a button or other object.
  181. -- Example:  removeVar cd,the id of me,fred
  182. --    a missing cardID means on the current card
  183. -- see getVar for the meaning of the arguments
  184.  
  185. put instVar(cdBk,myID,variable,"re{}move",cardID) into data
  186. -- this specal value means remove the variable from the dictionary
  187. end removeVar
  188.  
  189. -- Bonus handlers: removeVar, hasThisVar, allVarsOf
  190.  
  191. function hasThisVar cdBk,myID,variable,cardID
  192. -- Return true if this object has a variable of this name
  193. -- So a script can ask if the object has one before trying to read it.
  194. -- Example:  hasThisVar(cd,the id of me,"fred")
  195. --    a missing cardID means on the current card
  196. -- cdBk is cd or bk
  197. --    (where is this object? cd is card, bk is background)
  198. -- myID is: the short id of me
  199. -- variable is the name under which you want to store this value
  200. -- cardID (optional) the id of the card that contains the object
  201.  
  202. put "{" & variable & "{" & myID & "{" into startKey    --{Fred{21{
  203.  
  204. if cardID is empty
  205. then put the short id of this card into holder  -- on current card
  206. else put cardID into holder   --on a specific card
  207.  
  208. if cdBk = "bk"
  209. then put "call allowInstVars first" into theFld  --background objects
  210. else put "you must call allowInstVars" into theFld  --card specific
  211.  
  212. return offset(startKey,bkgnd fld theFld of cd id holder) is not 0
  213. end hasThisVar
  214.  
  215. function allVarsOf cdBk,myID,cardID
  216. -- Return a list of the names of the variables in this object now.
  217. -- Returns a list of items separated by commas
  218. -- Example:  allVarsOf(cd,the id of me)
  219. --    a missing cardID means on the current card
  220. -- cdBk is cd or bk
  221. --    (where is this object? cd is card, bk is background)
  222. -- myID is: the short id of me
  223. -- cardID (optional) the id of the card that contains the object
  224.  
  225. put "{" & myID & "{" into startKey    --{21{
  226.  
  227. if cardID is empty
  228. then put the short id of this card into holder  -- on current card
  229. else put cardID into holder   --on a specific card
  230.  
  231. if cdBk = "bk"
  232. then put "call allowInstVars first" into theFld  --background objects
  233. else put "you must call allowInstVars" into theFld  --card specific
  234.  
  235. put bkgnd fld theFld of cd id holder into rawData
  236. put empty into list
  237. repeat
  238. put offset(startKey,rawData) into index    --{21{
  239. if index = 0 then return list
  240. put index-1 into ii
  241. repeat until ii = 1    -- will not leave this way
  242. if char ii of rawData = "{" then
  243. if list is not empty then put "," after list
  244. put (char ii+1 to index-1 of rawData) after list   --fred
  245. delete char 1 to index+5 of rawData   -- remove start of this
  246. --     variable so the next one will be the first one found
  247. else
  248. subtract 1 from ii  --backup one char
  249. end if
  250. end repeat
  251. end repeat
  252. end allVarsOf
  253.  
  254. on ss
  255. -- For debugging only!  Show the raw data
  256. show bkgnd fld "you must call allowInstVars"
  257. show bkgnd fld "call allowInstVars first"
  258. end ss
  259.  
  260. on hh
  261. -- For debugging only!  Hide the raw data
  262. hide bkgnd fld "you must call allowInstVars"
  263. hide bkgnd fld "call allowInstVars first"
  264. end hh
  265. </script>
  266.     <background id="2801" file="background_2801.xml" name="" />
  267.     <card id="3026" file="card_3026.xml" marked="false" name="" owner="2801" />
  268.     <card id="6946" file="card_6946.xml" marked="false" name="" owner="2801" />
  269.     <card id="7375" file="card_7375.xml" marked="false" name="" owner="2801" />
  270.     <card id="7669" file="card_7669.xml" marked="false" name="" owner="2801" />
  271.     <card id="9254" file="card_9254.xml" marked="false" name="" owner="2801" />
  272.     <card id="7689" file="card_7689.xml" marked="false" name="" owner="2801" />
  273.     <card id="7940" file="card_7940.xml" marked="false" name="" owner="2801" />
  274.     <card id="3791" file="card_3791.xml" marked="false" name="" owner="2801" />
  275.     <card id="6694" file="card_6694.xml" marked="false" name="" owner="2801" />
  276.     <card id="9024" file="card_9024.xml" marked="false" name="" owner="2801" />
  277.     <card id="3928" file="card_3928.xml" marked="false" name="" owner="2801" />
  278.     <card id="8322" file="card_8322.xml" marked="false" name="" owner="2801" />
  279.     <card id="4497" file="card_4497.xml" marked="false" name="" owner="2801" />
  280.     <card id="5416" file="card_5416.xml" marked="false" name="" owner="2801" />
  281.     <card id="8462" file="card_8462.xml" marked="false" name="" owner="2801" />
  282.     <card id="4916" file="card_4916.xml" marked="false" name="" owner="2801" />
  283. </stack>
  284.